<?php

// response json
$json = array();

/**
 * Registering a user device
 * Store reg id in users table
 */
if (isset($_POST["name"]) && isset($_POST["email"]) && isset($_POST["regId"]) && isset($_POST["regId"])) {
    $name = $_POST["name"];
    $phone = $_POST["phone"];
    $gcm_regid = $_POST["regId"]; // GCM Registration ID
    $imsi = $_POST["imsi"];
    // Store user details in db
    include_once '../Model/mysql.php';
    include_once '../Model/GCM.php';
    include_once '../host_config.php';

    //$db = new DB_Functions();
    $db = new MySQL();
    $gcm = new GCM();
    //add by hashman
    $link = $db->connect($mysql_host, $mysql_user, $mysql_passwd, $mysql_db);
    $name = mysql_real_escape_string($name);
    $phone = mysql_real_escape_string($phone);
    $gcm_regid = mysql_real_escape_string($gcm_regid);
    $imsi = mysql_real_escape_string($imsi);

    $res = $db->storeUser($name, $phone, $gcm_regid, $imsi);

    $registatoin_ids = array($gcm_regid);
    $message = array("price" => "shirt");

    $result = $gcm->send_notification($registatoin_ids, $message);

    echo $result;
} else {
    // user details missing
}
?>